<template>
	<el-container>
		<el-container>
			<el-header>
                <div class="left-panel">
					<el-button type="primary" @click="add" v-auth="'spare.add'">新增</el-button>
					<el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'spare.deleteAll'">删除</el-button>
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="检验项目编号/名称" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
					<el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
					<el-table-column label="检验单编号" prop="check_code" align="center" width="120"></el-table-column>
					<el-table-column label="合格数量" prop="fcomqty" align="center" width="120"></el-table-column>
					<el-table-column label="不合格数量" prop="fnoqty" align="center" width="120"></el-table-column>
					<el-table-column label="检验项目" prop="name" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.name}}
                            </div>
                        </template>
                    </el-table-column>
					<el-table-column label="检验标准" prop="standard" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.standard}}
                            </div>
                        </template>
                    </el-table-column>
					<el-table-column label="检验方法" prop="method" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.method}}
                            </div>
                        </template>
                    </el-table-column>
					<!-- <el-table-column label="检验要求" prop="check_code" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.method}}
                            </div>
                        </template>
                    </el-table-column> -->
					<el-table-column label="检验值" prop="check_number" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.check_number}}
                            </div>
                        </template>
                    </el-table-column>
					<el-table-column label="是否合格" prop="is_qualified" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.is_qualified == 1 ? '合格':'不合格'}}
                            </div>
                        </template>
                    </el-table-column>
					<el-table-column label="上限" prop="upper" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.upper}}
                            </div>
                        </template>
                    </el-table-column>
					<el-table-column label="下限" prop="lower" align="center">
                        <template #default="scope">
                            <div v-for="item in scope.row.detail" :key="item.id">
                                {{item.lower}}
                            </div>
                        </template>
                    </el-table-column>
					<!-- <el-table-column label="工单编号" prop="work_plan.work_task_code" align="center"></el-table-column>
					<el-table-column label="物料编码" prop="product.goods_code" align="center"></el-table-column>
					<el-table-column label="物料名称" prop="product.goods_name" align="center"></el-table-column>
					<el-table-column label="物料类别" prop="product.cate_name" align="center"></el-table-column>
					<el-table-column label="物料规格" prop="product.goods_spec" align="center"></el-table-column>
					<el-table-column label="辅助属性" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="单位" prop="product.unit_name" align="center"></el-table-column>
					<el-table-column label="工序名称" prop="work.work_name" align="center"></el-table-column>
					<el-table-column label="是否委外" prop="work.is_out" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.is_out == 1 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.is_out == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="委外供应商" prop="apply_work.apply_name" width="100" align="center"></el-table-column>
					<el-table-column label="生产人员" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="报工数" prop="apply_work.work_number" align="center"></el-table-column>
					<el-table-column label="良品数" prop="customAddress" align="center">
                        <template #default="scope">
                            {{scope.row.apply_work&&scope.row.apply_work.work_number - scope.row.rejects_num}}
                        </template>
                    </el-table-column>
					<el-table-column label="不良品数" prop="rejects_num" align="center"></el-table-column>
					<el-table-column label="开始时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="结束时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="报工时长(时)" prop="customAddress" width="100" align="center"></el-table-column>
					<el-table-column label="报工时长(分)" prop="customAddress" width="100" align="center"></el-table-column>
					<el-table-column label="达标率" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="计价方式" prop="work.valuation_type" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.valuation_type == 0 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.valuation_type == 0 ?'计时':'计件'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="工资单价" prop="work.labor_piece" align="center"></el-table-column>
					<el-table-column label="预计工资" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="报工来源" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="已生成工资或费用" prop="customAddress" width="130" align="center"></el-table-column>
					<el-table-column label="需要检验" prop="customAddress" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.is_quality == 1 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.is_quality == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="检验方式" prop="work.quaqty_type" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.quaqty_type == 1 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.quaqty_type == 1 ?'全检':'抽检'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="抽检比例(%)" prop="work.quaqty_rate" width="100" align="center"></el-table-column>
					<el-table-column label="是否生成报检单" prop="customAddress" width="120" align="center"></el-table-column>
					<el-table-column label="合格数量" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="不合格数量" prop="customAddress" width="100" align="center"></el-table-column>
					<el-table-column label="单据编号" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="创建人" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="修改人" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="修改时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核人" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核日期" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核状态" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="备注" prop="customAddress" align="center"></el-table-column> -->
                    <el-table-column label="操作" fixed="right" align="center" width="170">
                        <template #default="scope">
                            <el-button-group>
                                <!-- <el-button text type="primary" size="small" @click="table_add(scope.row)">不良品项</el-button> -->
                                <el-button text type="primary" size="small" @click="table_show(scope.row)">查看</el-button>
                                <el-button text type="primary" size="small" @click="table_edit(scope.row)">编辑</el-button>
                                <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                                    <template #reference>
                                        <el-button text type="danger" size="small">删除</el-button>
                                    </template>
                                </el-popconfirm>
                            </el-button-group>
                        </template>
                    </el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
    <!-- <add-reason v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></add-reason> -->
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></save-dialog>
</template>

<script>
// import AddReason from './addReason.vue'
import saveDialog from './save.vue'
export default {
	name: 'user',
	// components: {AddReason},
    components: {saveDialog},
	data() {
		return {
			dialog: {
				save: false,
			},
			group: [],
			apiObj: this.$API.production.check.list,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
        }
	},
	methods: {
        add(){
            this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
        },
		table_edit(row){
            this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
        },
        table_show(row){
            this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show').setData(row)
			})
        },
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.production.check.delete.post(reqData);
			if (res.code == 1) {
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
		selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
